package com.kate.mall.common.valid.constraint;


import com.kate.mall.common.valid.Sex;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class SexConstraintValidator  implements ConstraintValidator<Sex,Integer> {
    /**
     * 性别约束逻辑
     * @param value
     * @param constraintValidatorContext
     * @return
     */
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        //如果value为null,那么该校验规则不生效;可搭配@NotNull注解使用,更加灵活
        if(value == null){
            return true;
        }
        return value==0|| value==1;
    }
}